﻿using System.Windows.Input;
using CommunityToolkit.Mvvm.Input;
using Klear.Library.Services;

namespace Klear.Library.ViewModels;

public class InitializationViewModel : ViewModelBase {
    private IDatabaseService _databaseService;
    private IRootNavigationService _rootNavigationService;
    private IMenuNavigationService _menuNavigationService;

    public InitializationViewModel(IDatabaseService databaseService,
        IRootNavigationService rootNavigationService,
        IMenuNavigationService menuNavigationService) {
        _databaseService = databaseService;
        _rootNavigationService = rootNavigationService;
        _menuNavigationService = menuNavigationService;
        OnInitializedCommand = new AsyncRelayCommand(OnInitialized);
    }
    
    private ICommand OnInitializedCommand { get; }

    public async Task OnInitialized() {
        if (!_databaseService.IsDatabaseInitialized()) {
            await _databaseService.InitializeAsync();
        }
        // 模拟延时
        await Task.Delay(1000);
        _rootNavigationService.NavigateTo(RootNavigationConstant.MainView);
        _menuNavigationService.NavigateTo(MenuNavigationConstant.IncomeExpensesView);
        
    }

}